Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" _
(ByVal hMenu As Long, _
ByVal un As Long, _
ByVal b As Long, _
lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, ByVal Length As Long)
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_MENUSELECT = &H11F
Private Const MF_BYCOMMAND = &H0&
Private Const MF_BYPOSITION = &H400&
Private Const MF_MENUBREAK = &H40&
Private Const MF_STRING = &H0&
Private Const MF_HELP = &H4000&
Private Const MFS_DEFAULT = &H1000&
Private Const MIIM_ID = &H2
Private Const MIIM_SUBMENU = &H4
Private Const MIIM_TYPE = &H10
Private Const MIIM_DATA = &H20
Private lOldWndProc As Long
Private lHook As Long
Private bIsHooked As Boolean
Private Function HookMessages(ByVal lhWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case msg
Case WM_MENUSELECT
Dim s$, l&, Low As Long
Dim mnu As MENUITEMINFO
s = Space(80)
With mnu
.cbSize = Len(mnu)
.dwTypeData = s & Chr(0)
.fType = MF_STRING
.cch = Len(.dwTypeData)
.fState = MFS_DEFAULT
.fMask = MIIM_ID Or MIIM_SUBMENU Or MIIM_DATA Or MIIM_TYPE
.hSubMenu = lParam
End With
Call CopyMem(Low, ByVal VarPtr(wParam), 2)
l = GetMenuItemInfo(lParam, Low, True, mnu)
If l = 0 Then
l = GetMenuItemInfo(lParam, Low, False, mnu)
End If
s = mnu.dwTypeData
s = Trim(Replace(Replace(s, Chr(0), ""), "&", ""))